$(function () {
    //发送请求
    //品牌大全
    $.ajax({
        type: "get",
        url: "http://193.112.55.79:9090/api/getbrandtitle",
        // data: "data",
        dataType: "json",
        success: function (res) {
            // console.log(res);
            var data = res.result;
            for (var i = 0; i < data.length; i++) {
                // console.log(data[i].brandTitleId);
                if (data[i].brandTitleId == id) {
                    // console.log(data[i]);
                    var a = data[i].brandTitle;
                    var b = data[i].brandTitle.split("十")[0];
                    var c = b + "哪个牌子好";
                    var d = b + "产品销量排行"
                    var e = b + "最有用的评论"
                    $(".a").html(c);
                    $(".nav_hot2").html(c);
                    $(".rank_header").html(d);
                    $(".comment_title").html(e);
                    // console.log(res);
                    
                }
            }
            var html = template('brandTmp',res);
            $('.brandTitle').html(html);
        }
    })

    //品牌大全分类
    var id = window.location.search.split('=')[1];
    $.ajax({
        type: "get",
        url: "http://193.112.55.79:9090/api/getbrand",
        data: {
            brandtitleid: id
        },
        dataType: "json",
        success: function (res) {
            // console.log(res);
            var html2 = template('brandIDTmp',res);
            $('.sortlist').html(html2);
        }
    });

    //销量排行
    $.ajax({
        type: "get",
        url: "http://193.112.55.79:9090/api/getbrandproductlist",
        data: {
            brandtitleid: id
        },
        dataType: "json",
        success: function (res) {
            console.log(res);
            var src = res.result[0].productImg;
            var name = res.result[0].productName;
            // console.log(name);
            var html3 = template('rankTmp',res);
            $('.rank_ul').html(html3);
            comment(src, name);
        }
    });
    
    //评价
    function comment(src,name) {
        $.ajax({
            type: "get",
            url: "http://193.112.55.79:9090/api/getproductcom",
            data: {
                productid: id
            },
            dataType: "json",
            success: function (res) {
                // console.log(name);
                var html4 = template('list1', {
                    lis: res.result,
                    src: src,
                    name: name
                })
                $('#comment').html(html4);
            }
        });
    }




})